<?php
class SearchAction extends PublicAction
{
    public function show()
    {
        $this->display();
    }

    public function search()
    {
        $url = C("SEARCH_API_URL");
        $ln  = C("SEARCH_LIST_LIMIT");
        $p   = isset($_GET["p"]) ? intval($_GET['p']) : 1;
        $w   = trim($_GET["w"]);
        /*if(strlen($w)==0){
            $this->redirect("show");
            return;
        }*/

        $url = str_replace("{1}",rawurlencode($w), $url);
        $url = str_replace("{2}",$p, $url);
        $url = str_replace("{3}",$ln, $url);
        
        $info = array();
        $news = array();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER ,true);
        $retStr = curl_exec($ch);
        curl_close($ch);
        
        if(!$retStr){
            $this->assign("hasError","true");
            $this->display();
            return;
        }

        $ret = json_decode($retStr, true);
      //  echo $url;
      //  dump($ret['info']);
        
       import("ORG.Util.Page");
       $pageNav = new Page($ret["info"]["recordcnt"],$ret["info"]["listcnt"],"w=$w");

        $this->assign("info",$ret["info"]);
        $this->assign("news",$ret["data"]);
        $this->assign("pageNav",$pageNav->show());

       $this->display();
    }
}
?>